<template>
    <view class="container">
        <view class="row-class">
<!--        <view class="title">授权登录</view>-->
        <view class="box">授权登录，主要用于完善您的个人资料，提供更好的使用体验～!</view>
            <view class="picker-buttons">
                <button class="btn1" @click="no">暂不登录</button>
                <button class="btn2" @click="ok">微信登录</button>
            </view>
        </view>
    </view>
</template>

<script setup>
    import { loginService } from '@/api/user.js'
    import { ref } from 'vue'
    const ok = (e) => {
        uni.showToast({ title: '登录中...', icon: 'none' })
        uni.login({
            provider: 'weixin',
            success(res) {
                console.log(res.code)
                let data = {
                    code: res.code
                }
                loginService(data).then(res => {
                    // getStorageSync
                    if(res.code ==200){
                        uni.setStorageSync('token', res.data)
                        uni.switchTab({
                            url: '/pages/layout/layout'
                        })
                    }

                })
                uni.hideLoading()
            },
            fail() {
                uni.hideLoading();
            }
        })
    }
    // const ok = (e) => {
    //     console.log(e, e.detail.userInfo) //用户信息
    //     if (e.detail.userInfo) {
    //         //如果拿到了用户信息，就将信息存到本地，在“我的”页面备用
    //         uni.setStorage({
    //             data: e.detail.userInfo,
    //             key: 'userInfo',
    //         })
    //         // app.globalData.userInfo = e.detail.userInfo
    //         uni.switchTab({
    //             url: '/pages/login/login'
    //         })
    //     }
    // }
    const no = (e) => {
        uni.switchTab({
            url: '/pages/layout/layout'
        })
    }
    //检查用户是否授权
    // uni.getSetting({
    //     success(res) {
    //         console.log(res.authSetting);
    //         // if (res.authsetting['scope.userInfo']) {
    //         //     console.log('存在')
    //         // } else {
    //         //     console.log('不存在')
    //         // }
    //     }
    // })
    // if (typeof uni.getSetting === 'function') {
    //     uni.getSetting({
    //         success(res) {
    //             console.log(res.authSetting);
    //         }
    //     });
    // } else {
    //     console.error('uni.getSetting is not supported on this platform.');
    // }
</script>

<style lang="scss" scoped>
    .container {
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        .row-class{
            padding: 100rpx;
            margin-top: -300rpx;
            .title {
                height: 100rpx;
                text-align: center;
            }
            .box {
                margin-bottom: 50rpx;
            }
        .picker-buttons {
            display: flex;
            text-align: center;
            width: 686rpx;
            gap: 60rpx;

            button {
                width: 313rpx;
                height: 78rpx;
                gap: 10rpx;
                font-size: 28rpx;
                border-radius: 100rpx;
                border: 2rpx solid rgba(79, 129, 240, 1);
                padding: 9rpx 20rpx;
            }

            .btn1 {
                background-color: rgba(79, 129, 240, 0.1);
                color: rgba(79, 129, 240, 1);

            }

            .btn2 {
                color: rgba(255, 255, 255, 1);
                background-color: rgba(79, 129, 240, 1);
            }
        }
        }
    }
</style>